package com.itheima.job;

import java.util.LinkedList;

public class Test06 {
    public static void main(String[] args) {
        LinkedList<Person1> linkedList = new LinkedList<>();
        Person1 p1 = new Person1("zs","man",10);
        Person1 p2 = new Person1("zs","man",12);
        Person1 p3 = new Person1("zs","woman",10);
        add(linkedList,p1);
        add(linkedList,p2);
        add(linkedList,p3);
        System.out.println(linkedList);
    }
    public static void add(LinkedList<Person1> linkedList,Person1 p){
        for (Person1 p1 : linkedList) {
            if (p1.equals(p)) {
                System.out.println("重复");
                return;
            }
        }
        linkedList.add(p);
    }
}

class Person1{
    private String name;
    private String sex;
    private Integer age;

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        Person1 person1 = (Person1) o;

        if (name != null ? !name.equals(person1.name) : person1.name != null) return false;
        return sex != null ? sex.equals(person1.sex) : person1.sex == null;
    }

    @Override
    public int hashCode() {
        int result = name != null ? name.hashCode() : 0;
        result = 31 * result + (sex != null ? sex.hashCode() : 0);
        return result;
    }

    @Override
    public String toString() {
        return "Person1{" +
                "name='" + name + '\'' +
                ", sex='" + sex + '\'' +
                ", age=" + age +
                '}';
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }

    public void setSex(String sex) {
        this.sex = sex;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Person1(String name, String sex, Integer age) {
        this.name = name;
        this.sex = sex;
        this.age = age;
    }

    public Person1() {
    }
}
